/*
 * LDIR
 * 
 * LDIR, a GPS cartography application built for Let's Do It Romania eco 
 * campaign.
 * Copyright (C) 2010 Genera Software <office@generasoftware.com>
 * 
 * http://generasoftware.com/
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */
#include <aknviewappui.h>
#include <eikappui.h>
#include <LDIR.rsg>
#include "LDIRMap.h"
#include "LDIRMapView.h"
#include "LDIR.hrh"

/**
 * First phase of Symbian two-phase construction. Should not 
 * contain any code that could leave.
 */
CLDIRMap::CLDIRMap()
    {
    }
/** 
 * Destroy child controls.
 */
CLDIRMap::~CLDIRMap()
    {
    
    }
                
/**
 * Construct the control (first phase).
 *  Creates an instance and initializes it.
 *  Instance is not left on cleanup stack.
 * @param aRect bounding rectangle
 * @param aParent owning parent, or NULL
 * @param aCommandObserver command observer
 * @return initialized instance of CLDIRMap
 */
CLDIRMap* CLDIRMap::NewL( 
        const TRect& aRect, 
        const CCoeControl* aParent, 
        MEikCommandObserver* aCommandObserver )
    {
    CLDIRMap* self = CLDIRMap::NewLC( 
            aRect, 
            aParent, 
            aCommandObserver );
    CleanupStack::Pop( self );
    return self;
    }

/**
 * Construct the control (first phase).
 *  Creates an instance and initializes it.
 *  Instance is left on cleanup stack.
 * @param aRect The rectangle for this window
 * @param aParent owning parent, or NULL
 * @param aCommandObserver command observer
 * @return new instance of CLDIRMap
 */
CLDIRMap* CLDIRMap::NewLC( 
        const TRect& aRect, 
        const CCoeControl* aParent, 
        MEikCommandObserver* aCommandObserver )
    {
    CLDIRMap* self = new ( ELeave ) CLDIRMap();
    CleanupStack::PushL( self );
    self->ConstructL( aRect, aParent, aCommandObserver );
    return self;
    }
            
/**
 * Construct the control (second phase).
 *  Creates a window to contain the controls and activates it.
 * @param aRect bounding rectangle
 * @param aCommandObserver command observer
 * @param aParent owning parent, or NULL
 */ 
void CLDIRMap::ConstructL( 
        const TRect& aRect, 
        const CCoeControl* aParent, 
        MEikCommandObserver* aCommandObserver )
    {
    if ( aParent == NULL )
        {
        CreateWindowL();
        }
    else
        {
        SetContainerWindowL( *aParent );
        }
    iFocusControl = NULL;
    iCommandObserver = aCommandObserver;
    InitializeControlsL();
    SetRect( aRect );
    ActivateL();
    }
            
/**
* Return the number of controls in the container (override)
* @return count
*/
TInt CLDIRMap::CountComponentControls() const
    {
    return ( int ) ELastControl;
    }
                
/**
* Get the control with the given index (override)
* @param aIndex Control index [0...n) (limited by #CountComponentControls)
* @return Pointer to control
*/
CCoeControl* CLDIRMap::ComponentControl( TInt aIndex ) const
    {
    switch ( aIndex )
        {
        }
    // handle any user controls here...
    
    return NULL;
    }
                
/**
 *    Handle resizing of the container. This implementation will lay out
 *  full-sized controls like list boxes for any screen size, and will layout
 *  labels, editors, etc. to the size they were given in the UI designer.
 *  This code will need to be modified to adjust arbitrary controls to
 *  any screen size.
 */                
void CLDIRMap::SizeChanged()
    {
    CCoeControl::SizeChanged();
    LayoutControls();
    }
                
/**
 * Layout components as specified in the UI Designer
 */
void CLDIRMap::LayoutControls()
    {
    }

/**
 *    Handle key events.
 */                
TKeyResponse CLDIRMap::OfferKeyEventL( 
        const TKeyEvent& aKeyEvent, 
        TEventCode aType )
    {
    if ( iFocusControl != NULL
        && iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
        {
        return EKeyWasConsumed;
        }
    return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
    }
                
/**
 *    Initialize each control upon creation.
 */                
void CLDIRMap::InitializeControlsL()
    {
    
    }

/** 
 * Handle global resource changes, such as scalable UI or skin events (override)
 */
void CLDIRMap::HandleResourceChange( TInt aType )
    {
    CCoeControl::HandleResourceChange( aType );
    SetRect( iAvkonViewAppUi->View( TUid::Uid( ELDIRMapViewId ) )->ClientRect() );
    }
                
/**
 *    Draw container contents.
 */                
void CLDIRMap::Draw( const TRect& aRect ) const
    {
    CWindowGc& gc = SystemGc();
    gc.Clear( aRect );
    }
                
